package com.knav.inject;

import android.app.Activity;
import android.content.Context;

import androidx.appcompat.app.AppCompatActivity;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class RegisterActivityInject {

    private Class<? extends Activity> ActivityInject = AppCompatActivity.class;

    public static RegisterActivityInject builder(Context context) {

        return new RegisterActivityInject();
    }

    private boolean dispatchActivity(Activity activity) throws Exception {
        Class<? extends Activity> subClass = this.ActivityInject.asSubclass(Activity.class);
        Dispatcher dispatcher = new Dispatcher();
        Field[] fields = subClass.getFields();
        Method[] methods = subClass.getMethods();
        dispatcher.dispatcherActivity(subClass, activity, fields, methods);

        return true;
    }

    public void registerActivityFind(Class<? extends Activity> imp, Activity activity) {
        this.ActivityInject = imp;
        try {
            dispatchActivity(activity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
